package com.saoft.fangcms.modules.sys.mapper;

import com.saoft.fangcms.common.constant.StatusConst;
import com.saoft.fangcms.modules.sys.entity.Menu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author scc95599
 * @since 2019-12-24
 */
public interface MenuMapper extends BaseMapper<Menu> {


    @Select("select sm.* from sys_menu sm LEFT JOIN sys_role_menu srm ON sm.id = srm.menu_id where srm.role_id=#{roleId}")
    List<Menu> getMenusByRoleId(@Param("roleId") Long roleId);


    @Select("select max(sort) from Menu m where m.pid = #{pid} and m.status <> " + StatusConst.DELETE)
    Integer findSortMax(@Param("pid")long pid);

    @Update("DELETE FROM sys_role_menu WHERE menu_id = #{menuId}")
    void cancelRoleJoin(@Param("menuId")long menuId);
}
